import * as path from "path";
import * as fs from "fs";
import { IAuthOptions } from "./lib/uni_auth/router";
export interface IPortConfig {
  port: string;
}
export interface IAppConfig extends IAuthOptions, IPortConfig {}
export function getConfig(): IAppConfig {
  let config;
  const defaultConfigPath = path.resolve(__dirname, "../config.default.json");
  const userConfigPath = path.resolve(__dirname, "../config.user.json");
  if (fs.existsSync(defaultConfigPath)) {
    config = JSON.parse(
      (fs.readFileSync(defaultConfigPath) as unknown) as string
    ) as IAppConfig;
  }
  if (fs.existsSync(userConfigPath)) {
    config = Object.assign(
      config,
      JSON.parse(
        (fs.readFileSync(userConfigPath) as unknown) as string
      ) as IAppConfig
    );
  }
  return config;
}
